package cn.cimoc.handler;

import cn.cimoc.constant.ErrorEnum;
import cn.cimoc.model.vo.ResultVO;
import cn.cimoc.util.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author LGZ
 * @date 2022/7/15 19:20
 * <p>
 */
@ControllerAdvice
public class HttpMediaTypeNotSupportedExceptionHandler {
    private  final Logger log = LoggerFactory.getLogger(HttpMediaTypeNotSupportedExceptionHandler.class);

    @ExceptionHandler(value = HttpMediaTypeNotSupportedException.class)
    @ResponseBody
    public ResultVO error(HttpMediaTypeNotSupportedException e) {
        log.info("前端传入数据格式错误: " + e.getMessage());
        return CommonUtils.ajaxReturn(ErrorEnum.BAD_REQUEST);
    }
}
